package com.hqyj.springboot.modules.account.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.hqyj.springboot.modules.account.entity.Role;
import com.hqyj.springboot.modules.common.vo.Result;
import com.hqyj.springboot.modules.common.vo.Search;
import com.hqyj.springboot.modules.account.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 127.0.0.1:8081/api/roles   post
     * {"currentPage":1,"pageSize":2,"sort":"roleName","direction":"desc","keyword":""}
     */
//    @PostMapping(value = "/roles",consumes = "application/json")
//    public Page getRolesBySearch(@RequestBody Search search) {
//
//        return roleService.getRolesBySearch(search);
//    }

    @PostMapping(value = "/role",consumes = "application/json")
    public Result<Role> addRole(Role role){
        return roleService.addRole(role);
    }

    @PutMapping(value = "/role",consumes = "application/json")
    public Result<Role> updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    @DeleteMapping("/role/{id}")
    public Result<Object> deleteRoleById(@PathVariable int id){
        return roleService.deleteRoleById(id);
    }

    @GetMapping("/roles")
    public List<Role> getRoles(){
        return roleService.getRoles();
    }

    @GetMapping("/role/{id}")
    public Role getRoleById(@PathVariable int id){
        return roleService.getRoleById(id);
    }

    @PostMapping(value = "/roles",consumes = "application/json")
    public PageInfo<Role> getRolesBySearchBean(@RequestBody Search search){
        return roleService.getRolesBySearchBean(search);
    }

    @GetMapping("/roles/{userId}")
    public List<Role> getRolesByUserId(@PathVariable int userId){
        return roleService.getRolesByUserId(userId);
    }





}
